package com.yuye.cloud.common.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yuye.cloud.common.lock.DistributedLock;

/**
 * service接口父类
 *
 * @author xgf
 */
public interface ISuperService<T> extends IService<T> {
    /**
     * 幂等性新增记录
     *
     * Description:
     * 例子： String username = sysUser.getUsername();
     * boolean result = super.saveIdempotency(sysUser, lock;
     * , LOCK_KEY_USERNAME+username;
     * , new QueryWrapper &lt;SysUser %gt; ().eq("username", username));
     *
     * @param entity       实体对象
     * @param locker       锁实例
     * @param lockKey      锁的key
     * @param countWrapper 判断是否存在的条件
     * @param msg          对象已存在提示信息
     * @return boolean
     * @throws Exception 异常
     */
    boolean saveIdempotency(T entity, DistributedLock locker, String lockKey, Wrapper<T> countWrapper, String msg) throws Exception;

    /**
     * 幂等性新增记录
     *
     * @param entity       实体对象
     * @param locker       锁实例
     * @param lockKey      锁的key
     * @param countWrapper 判断是否存在的条件
     * @return boolean
     * @throws Exception 异常
     */
    boolean saveIdempotency(T entity, DistributedLock locker, String lockKey, Wrapper<T> countWrapper) throws Exception;

    /**
     * 幂等性新增或更新记录
     *
     * @param entity       实体对象
     * @param locker       锁实例
     * @param lockKey      锁的key
     * @param countWrapper 判断是否存在的条件
     * @param msg          对象已存在提示信息
     * @throws Exception 异常
     * @return boolean
     */
    boolean saveOrUpdateIdempotency(T entity, DistributedLock locker, String lockKey, Wrapper<T> countWrapper, String msg) throws Exception;

    /**
     * 幂等性新增或更新记录
     *
     * @param entity       实体对象
     * @param locker       锁实例
     * @param lockKey      锁的key
     * @param countWrapper 判断是否存在的条件
     * @throws Exception 异常
     * @return boolean
     */
    boolean saveOrUpdateIdempotency(T entity, DistributedLock locker, String lockKey, Wrapper<T> countWrapper) throws Exception;
}
